import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { viteMockServe } from 'vite-plugin-mock';
import ViteComponents, { AntDesignVueResolver } from 'vite-plugin-components';
import path from 'path';
import { svgBuilder } from './src/plugins/svgBuilder';
import vueI18n from '@intlify/vite-plugin-vue-i18n';

// https://vitejs.dev/config/
export default ({ command }) => {
  const prodMock = false;
  return defineConfig({
    plugins: [
      vue(),
      vueJsx({}),
      viteMockServe({
        localEnabled: command === 'serve' && prodMock,
        prodEnabled: command !== 'serve' && prodMock,
        injectCode: `
                import { setupProdMockServer } from '../mock/mockServe';
                setupProdMockServer();
            `
      }),
      svgBuilder('./src/icons/svg/')
      // vueI18n({
      // if you want to use Vue I18n Legacy API, you need to set `compositionOnly: false`
      // compositionOnly: false,
      // you need to set i18n resource including paths !
      // include: path.resolve(__dirname, './path/to/src/locales/**')
      // }),
      /**按需加载的插件，但是与主题设置冲突，所以暂时先不启用
              ViteComponents({
                customComponentResolvers: [AntDesignVueResolver()],
              }),
            */
    ],
    resolve: {
      alias: {
        '@': path.join(__dirname, 'src')
      }
    },
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {
            'primary-color': '#1890ff',
            'link-color': '#1890ff',
            'border-radius-base': '4px'
          },
          javascriptEnabled: true
        }
      }
    },
    server: {
      proxy: {
        // 选项写法
        '/qms': {
          logLevel: 'debug',
          // target : 'http://qms-server-test.earth.xpaas.lenovo.com/',
          // target: 'http://10.176.120.236:5000', //刘健地址
          // target: 'http://localhost:5000', // 本地
          target: 'http://10.176.116.118:5000', // 张亚地址
          // target: 'http://10.176.115.78:5000', // 海坤地址
          // target: 'http://10.176.108.33:5000', // 超哥地址
          //  rewrite: path => path.replace(/^\/api/, ''), // 重写传过来的path路径，比如 `/api/index/1?id=10&name=zs`（注意:path路径最前面有斜杠（/），因此，正则匹配的时候不要忘了是斜杠（/）开头的；选项的 key 也是斜杠（/）开头的）
          changeOrigin: true // true/false, Default: false - changes the origin of the host header to the target URL
        }
      }
    }
  });
};
